#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>


static void Test01() {
	int n, m;
	scanf("%d%d", &n, &m);

	std::vector<int> nodes(n, 0);

	std::vector<std::vector<int>> graph(n, std::vector<int>(n, 0));

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			scanf("%d", &graph[i][j]);
		}
		nodes[i] = i;
	}

	printf("%d\n", n - 1);
	for (const int& node : nodes) {
		if (node != m) {
			printf("%d", node);
		}
	}

	printf("\n");

	for (int i = 0; i < n; i++) {
		if (i == m) {
			continue;
		}
		for (int j = 0; j < n; j++) {
			if (j == m) {
				continue;
			}
			printf("%d ", graph[i][j]);
		}
		printf("\n");
	}
}


static void Test02() {
	int n, m;
	scanf("%d%d", &n, &m);
	int graph[110][110];

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			scanf("%d", &graph[i][j]);
		}
	}

	printf("%d\n", n - 1);

	for (int i = 0; i < n; i++) {
		if (i != m) {
			printf("%d", i);
		}
	}
	printf("\n");

	for (int i = 0; i < n; i++) {
		if (i == m) {
			continue;
		}
		for (int j = 0; j < n; j++) {
			if (i != m && j != m) {
				printf("%d", graph[i][j]);
			}
		}
		printf("\n");

	}
}

static void Test03() {
	int n, m;
	scanf("%d%d", &n, &m);

	std::vector<int> nodes(n, 0);

	std::vector<std::vector<int>> graph(n, std::vector<int>(n, 0));

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			scanf("%d", &graph[i][j]);
		}
		nodes[i] = i;
	}

	printf("%d\n", n - 1);
	nodes.erase(nodes.begin() + m);
	for (const int& node : nodes) {
		printf("%d", node);
	}

	printf("\n");

	graph.erase(graph.begin() + m);

	for (std::vector<int>& row : graph) {
		row.erase(row.begin() + m);
	}


	for (int i = 0; i < n-1; i++) {
		for (int j = 0; j < n-1; j++) {
			printf("%d", graph[i][j]);
		}
		printf("\n");
	}
}


/**
 * 
 * 删除顶点
 * 
 * 5 2
0 1 0 1 0
0 0 1 1 0
0 0 0 0 0
0 0 0 0 0
1 0 0 1 0
 * @return
 */
int main() {


	Test03();


	return 0;
}